//
//  LVBaseCollectionViewModel.m
//  BaseCode
//
//  Created by 曹连华 on 2019/6/20.
//  Copyright © 2019 曹连华. All rights reserved.
//

#import "LVBaseCollectionViewModel.h"

@interface LVBaseCollectionViewModel ()

@property (nonatomic, strong) LVCollectionViewDataSource *dataSource;

@end

@implementation LVBaseCollectionViewModel

- (LVCollectionViewDataSource *)dataSource {
    if (!_dataSource) {
        _dataSource = [[LVCollectionViewDataSource alloc]init];
    }
    return _dataSource;
}
- (void)initOperateBlock {

    self.dataSource.moveRowModelBlock = ^(RowModelEditOperateResultBlock  _Nullable operateResultBlock, NSIndexPath * _Nullable sourceIndexPath, NSIndexPath * _Nullable destinationIndexPath) {
        operateResultBlock(YES);
    };
}
- (void)reloadCollectionView {
    if(self.reloadCollectionBlock) {
        self.reloadCollectionBlock(nil, nil);
    }
}

- (void)reloadCollectionViewWithIndexPaths:(NSArray<NSIndexPath *> *)indexPaths {
    if(self.reloadCollectionBlock) {
        self.reloadCollectionBlock(nil, indexPaths);
    }
}

- (void)reloadCollectionViewWithSections:(NSIndexSet *)sections {
    if(self.reloadCollectionBlock) {
        self.reloadCollectionBlock(sections, nil);
    }
}

- (LVBaseCellRowModel *)didSelectedRowModelWithIndexPath:(NSIndexPath *)indexPath {
    return [self didSelectedRowModelWithIndexPath:indexPath completionBlock:nil];
}

- (LVBaseCellRowModel *)didSelectedRowModelWithIndexPath:(NSIndexPath *)indexPath completionBlock:(nullable LVCompletionBlock)completionBlock {
    if (completionBlock) {
        completionBlock(nil);
    }
    return [self.dataSource rowModelAtIndex:indexPath];
}
- (void)dealloc {
    NSLog(@"LVBaseCollectionViewModel - dealloc");
}
@end
